﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.BLL.InfoConfig;
using MINERP.MODEL.FoundationModel;

namespace MINERP.InfoConfig
{
    public partial class FrmTechCommomChargeItem : Form
    {
        public FrmTechCommomChargeItem()
        {
            InitializeComponent();
        }
        private static FrmTechCommomChargeItem _instance;

        public static FrmTechCommomChargeItem CreateInstance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new FrmTechCommomChargeItem();
                }
                return _instance;
            }
        }
        private TechCommomChargeItemBLL _bll = new TechCommomChargeItemBLL();
        List<TechCommonChargeItem_Info> listCommonChargeItem = new List<TechCommonChargeItem_Info>();


        private void FrmTechCommomChargeItem_Load(object sender, EventArgs e)
        {
            gcSelect.OptionsColumn.ReadOnly = true;
            simpleButtonSave.Enabled = false;
            List<Tb_Tech_Info> AllTech = _bll.GetAllTech();
            gridControlTech.DataSource = AllTech;
        }

        private void gridViewTech_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            //if(e.RowHandle==0)
            //{
            //    Tb_Tech_Info info = (Tb_Tech_Info) gridViewTech.GetRow(e.RowHandle);
            //    gridControlCommonItems.DataSource = _bll.GetTechComm(info.TechId);
            //}
        }

        private void gridViewTech_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
              Tb_Tech_Info info = (Tb_Tech_Info) gridViewTech.GetFocusedRow();
              gridControlCommonItems.DataSource = listCommonChargeItem=_bll.GetTechComm(info.TechId);
            
        }

        private void btnUpdateShop_Click(object sender, EventArgs e)
        {
            gcSelect.OptionsColumn.ReadOnly = false;
            simpleButtonSave.Enabled = true;
        }

        private void simpleButtonSave_Click(object sender, EventArgs e)
        {
            simpleButtonSave.Enabled = false;
            List<TechCommonChargeItem_Info> list = listCommonChargeItem;
            Tb_Tech_Info info = (Tb_Tech_Info)gridViewTech.GetFocusedRow();
            try
            {
                this.Cursor = Cursors.WaitCursor;
                int rtnInt = _bll.UpdataTechCommonChargeIte(info.TechId,list);
                if(rtnInt==0)
                {
                    MessageBox.Show("保存成功", " 提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, " 提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ;
            }
            finally
            {
                this.Cursor = Cursors.Default;
                simpleButtonSave.Enabled = true;
            }
            gcSelect.OptionsColumn.ReadOnly = true;
        }

        private void simpleButtonCancel_Click(object sender, EventArgs e)
        {
            gcSelect.OptionsColumn.ReadOnly = true;
            simpleButtonSave.Enabled = false;
        }

        private void FrmTechCommomChargeItem_FormClosing(object sender, FormClosingEventArgs e)
        {
            _instance = null;
        }
    }
}
